package com.zy.design.pattern.template.original;

import java.sql.*;

/**
 * @author zhaoyi
 * @date 2021/7/28 11:17
 * <p>
 * 原始的方式查询对象
 */
public class Case {


    public static void main(String[] args) {
        Connection conn = null;
        Statement stmt = null;
        //1.加载驱动
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://10.0.10.54:3306/cia_test", "bftest", "bf@test2020");
            stmt = conn.createStatement();
            ResultSet resultSet = stmt.executeQuery("select id, title from tb_awards limit 2;");
            while (resultSet.next()) {
                User user = new User();
                user.setId(resultSet.getInt("id"));
                user.setTitle(resultSet.getString("title"));
                System.out.println(user);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }


}
